home *** CD-ROM | disk | FTP | other *** search
- /*
- ** $VER: dofile.rexx 2.1 (4.2.96) Rolf Rotvel
- **
- ** Uses datatypes.library & rexxreqtools.library
- */
-
- cfgfile = 'env:dofile.prefs' /* Path to prefs file */
- defdir = 'txt:' /* Defdir for filerequester */
- multicmd = 'sys:utilities/multiview screen' /* Path (& options) to Multiview */
-
- /*
- ** End cfg.
- */
-
- /* Load libraries */
- call addlib('rexxsupport.library', 0, -30, 0)
- call addlib('rexxreqtools.library', 0, -30, 0)
- call addlib('datatypes.library', 0, -30)
-
- /* Get version info from $VER line */
- version = subword(sourceline(2), 3, 2)
- /* Check defdir */
- if defdir = '' | ~exists(defdir) then defdir = pragma('d')
-
- /* Open cfgfile - exit if fail - read it otherwise */
- if ~open('tmp', cfgfile, 'r') then do
- call rtezrequest('Couldn''t open '||cfgfile,, version)
- exit 10
- end
- cfg = upper(' '||translate(readch('tmp', 65535), '', '0a'x))
- call close('tmp')
-
- /* If no arg then open filerequester */
- if arg() = 0 then txt = gettxt(defdir)
- else do
- /* Get args and remove quotes - if any */
- txt = strip(arg(1), 'b', '"')
- /* Handle special cases (File = .info or file = dir) */
- select
- when ~exists(txt) then txt = txt||'.info'
- when word(statef(txt), 1) = 'DIR' then txt = gettxt(txt)
- otherwise nop
- end
- end
-
- txt = upper(txt)
-
- /* Simple error handling */
- if ~exists(txt) then exit 10
- if word(statef(txt), 2) = 0 then exit 10
-
- /* Get (data)type of file */
- type = upper(filetype(txt))
-
- /* Check ascii & binary files for special cases */
- if type = 'ASCII' | type = 'BINARY' then do
- name = getname(txt)
- parse upper var name base '.' suff
- /* Filename has an extension */
- if suff ~= '' then do
- /* We found a match in cfg file */
- if pos(' .'||suff||' ', cfg) > 0 then type = '.'||suff
- /* No match -> check binary files for MOD. type names */
- if type = 'BINARY' then do
- if pos(' '||base||'. ', cfg) > 0 then type = base||'.'
- end
- end
- end
-
- /* Didn't find any file to process? */
- if type = 'BINARY' then do
- /* Check for binary entry in cfg file */
- if pos(' '||type||' ', cfg) = 0 then do
- call rtezrequest('Couldn''t process:'||'0a'x||txt,, version)
- exit
- end
- end
-
-
- /* Find the cmd associated with the filetype and do it */
- type = ' '||type||' '
- parse var cfg . (type) '"' cmd '"' .
- /* Fall back on Multiview */
- if cmd = '' then cmd = upper(multicmd)
- say strip(type)||' -> '||cmd
-
- /* Do it! */
- signal on failure
- address command cmd '"'||txt||'"'
- exit
-
-
- GETTXT:
- parse arg dir
- txt = rtfilerequest(dir,, version,, 'rt_screentofront=true')
- if txt = '' then exit
- return strip(txt, 'b', '"')
-
- FILETYPE: procedure
- parse arg file
- return strip(translate(examinedt(file,,), '', '0'x))
-
- GETNAME: procedure
- parse arg path
- return strip(substr(path, max(pos(':', path), lastpos('/', path)) + 1))
-
- FAILURE:
- exit
-